package com.gouaixin.bee.beeframework2;

import android.app.Application;
import android.content.Context;
import android.view.WindowManager;

import com.bx.pay.BXPay;
import com.google.gson.Gson;
import com.gouaixin.bee.beeframework2.bean.BaiduMapResponse;
import com.gouaixin.bee.beeframework2.bean.BaseModel;
import com.gouaixin.bee.beeframework2.tool.PreferencesUtils;
import com.gouaixin.bee.beeframework2.tool.mLog;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;

/**
 * Created by Administrator on 2015/3/25.
 */
//应用整体配置
public class MyApplication extends Application {
   static Context context;

    @Override
    public void onCreate() {

        context=getApplicationContext();
        //在使用SDK各组件之前初始化context信息，传入ApplicationContext
        //注意该方法要再setContentView方法之前实现
//        SDKInitializer.initialize(getApplicationContext());

        //配置iamgeloader（有缓存）
        DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
                .cacheInMemory().cacheOnDisc().build();

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                context).defaultDisplayImageOptions(defaultOptions)
                .threadPriority(Thread.NORM_PRIORITY - 2)
                .threadPoolSize(10) // default  线程池内加载的数量
                .denyCacheImageMultipleSizesInMemory()
                .discCacheFileNameGenerator(new Md5FileNameGenerator())
                .tasksProcessingOrder(QueueProcessingType.LIFO).build();
        ImageLoader.getInstance().init(config);

        BXPay bxpay = new BXPay(context);
        bxpay.init(context);

//        initCity();

//        SMSSDK.initSDK(this,
//                "732340ec6b34",
//                "d03a78efdae0b38ef9e50ccace5d48ac");
//
//
//        super.onCreate();

    }

    public static void initCity() {
        String weburl="http://api.map.baidu.com/location/ip?ak=GkNCBcRz1cmpwfgjcjDrR7lq";

        mLog.e("weburl" + weburl);

        BaseModel.setCallBackLister(new BaseModel.CallBackLister() {
            @Override
            public String onCallBack(String url, String result) {

                BaiduMapResponse response=new Gson().fromJson(result,BaiduMapResponse.class);
                String address=response.getContent().getAddress();
                String city=response.getContent().getAddress_detail().getCity();

                mLog.e("address=" + address);
                mLog.e("city=" + city);

                PreferencesUtils.putString(context, "address", address);
                PreferencesUtils.putString(context,"city",city);



                return "";

            }
        });
        BaseModel.get(weburl);


    }

    private WindowManager.LayoutParams wmParams=new WindowManager.LayoutParams();

    public WindowManager.LayoutParams getMywmParams(){
        return wmParams;
    }

//    /**
//     * 创建全局变量
//     * 全局变量一般都比较倾向于创建一个单独的数据类文件，并使用static静态变量
//     *
//     * 这里使用了在Application中添加数据的方法实现全局变量
//     * 注意在AndroidManifest.xml中的Application节点添加android:name=".MyApplication"属性
//     *
//     */
//    private WindowManager.LayoutParams wmParams=new WindowManager.LayoutParams();
//
//
//    public WindowManager.LayoutParams getMywmParams(){
//        return wmParams;
//    }


}
